home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / text / hyper / hsc_source.lha / hsc / source / hsclib / hscprc.c < prev    next >
C/C++ Source or Header  |  1996-11-04  |  18KB  |  802 lines

  1. /*
  2.  * hscprc.c
  3.  *
  4.  * hsc process functions
  5.  *
  6.  * Copyright (C) 1995,96  Thomas Aglassinger
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  * updated: 31-Oct-1996
  23.  * created: 11-Feb-1996
  24.  */
  25.  
  26. #define NOEXTERN_HSCLIB_HSCPRC
  27.  
  28. #include "hsclib/inc_base.h"
  29.  
  30. #include "ugly/fname.h"
  31. #include "ugly/ustrlist.h"
  32. #include "ugly/returncd.h"
  33.  
  34. #include "hscprj/project.h"
  35.  
  36. #include "hsclib/idref.h"
  37. #include "hsclib/tag_if.h"
  38.  
  39. /*
  40.  * del_inpf_stack_node
  41.  *
  42.  * remove node from input file stack
  43.  */
  44. static VOID del_inpf_stack_node(APTR data)
  45. {
  46.     /* do nufin */
  47. }
  48.  
  49. /*
  50.  * del_hscprc
  51.  *
  52.  * remove hsc process and all it's resources
  53.  */
  54. VOID del_hscprc(HSCPRC * hp)
  55. {
  56.     if (hp)
  57.     {
  58.         /* remove list */
  59.         del_dllist(hp->defent);
  60.         del_dllist(hp->deftag);
  61.         del_dllist(hp->defattr);
  62.         del_dllist(hp->container_stack);
  63.         del_dllist(hp->inpf_stack);
  64.         del_dllist(hp->idrefs);
  65.         del_dllist(hp->select_stack);
  66.         del_strlist(hp->include_dirs);
  67.  
  68.         /* remove strings */
  69.         del_estr(hp->destdir);
  70.         del_estr(hp->reldir);
  71.         del_estr(hp->iconbase);
  72.         del_estr(hp->if_stack);
  73.         del_estr(hp->tag_name_str);
  74.         del_estr(hp->tag_attr_str);
  75.         del_estr(hp->tag_close_str);
  76.         del_estr(hp->tmpstr);
  77.         del_estr(hp->rmt_str);
  78.         del_estr(hp->curr_msg);
  79.         del_estr(hp->curr_ref);
  80.         del_estr(hp->whtspc);
  81.  
  82.         ufreestr(hp->filename_document);
  83.         ufreestr(hp->strip_tags);
  84.  
  85.         /* remove project-data */
  86.         del_project(hp->project);
  87.  
  88.         /* close input files */
  89.         infclose(hp->inpf);
  90.  
  91.         /* remove message arrays */
  92.         ufree(hp->msg_ignore);
  93.         ufree(hp->msg_class);
  94.  
  95.         ufree(hp);
  96.     }
  97. }
  98.  
  99. /*
  100.  * reset_hscprc
  101.  *
  102.  * reset all items of a hsc process
  103.  */
  104. VOID reset_hscprc(HSCPRC * hp)
  105. {
  106.     int i;
  107.  
  108.     /* get current time */
  109.     hp->start_time = time(NULL);
  110.  
  111.     /* reset strings */
  112.     clr_estr(hp->destdir);
  113.     clr_estr(hp->reldir);
  114.     clr_estr(hp->if_stack);
  115.     clr_estr(hp->whtspc);
  116.  
  117.     hp->suppress_output = TRUE;
  118.     hp->fatal = FALSE;
  119.     hp->prev_heading_num = 0;
  120.     hp->prev_status_line = (ULONG) - 1;
  121.     hp->msg_count = 0;
  122.  
  123.     hp->inside_pre = FALSE;
  124.     hp->inside_anchor = FALSE;
  125.     hp->inside_title = FALSE;
  126.  
  127.     hp->strip_badws = FALSE;
  128.     hp->strip_next_whtspc = FALSE;
  129.     hp->strip_next2_whtspc = FALSE;
  130.  
  131.     ufreestr(hp->strip_tags);
  132.  
  133.     /* check for prostitute */
  134.     hp->prostitute = (getenv(ENV_HSCSALARY) != NULL);
  135.  
  136.     /* reset messages */
  137.     hp->msg_ignore_notes = FALSE;
  138.     hp->msg_ignore_style = FALSE;
  139.     hp->msg_ignore_port = FALSE;
  140.     for (i = 0; i < MAX_MSGID; i++)
  141.     {
  142.         hp->msg_ignore[i] = FALSE;
  143.         hp->msg_class[i] = MSG_NOTE;
  144.     }
  145. }
  146.  
  147. /*
  148.  * new_hscprc
  149.  *
  150.  * create and init a new hsc process
  151.  */
  152. HSCPRC *new_hscprc(void)
  153. {
  154.     HSCPRC *hp = NULL;
  155.  
  156.     hp = (HSCPRC *) umalloc(sizeof(HSCPRC));
  157.     if (hp)
  158.     {
  159.         memset(hp, 0, sizeof(HSCPRC));
  160.  
  161.         /* init lists */
  162.         hp->defent = init_dllist(del_entity);
  163.         hp->deftag = init_dllist(del_hsctag);
  164.         hp->defattr = init_dllist(del_hscattr);
  165.         hp->container_stack = init_dllist(del_hsctag);
  166.         hp->inpf_stack = init_dllist(del_inpf_stack_node);
  167.         hp->project = NULL;
  168.         hp->idrefs = init_dllist(del_idref);
  169.         hp->select_stack = init_dllist(del_select_stack_node);
  170.         hp->include_dirs = init_strlist();
  171.  
  172.         /* init strings */
  173.         hp->destdir = init_estr(0);
  174.         hp->reldir = init_estr(0);
  175.         hp->iconbase = init_estr(0);
  176.         hp->if_stack = init_estr(0);
  177.         hp->tag_name_str = init_estr(128);
  178.         hp->tag_attr_str = init_estr(128);
  179.         hp->tag_close_str = init_estr(0);
  180.         hp->tmpstr = init_estr(0);
  181.         hp->rmt_str = init_estr(128);
  182.         hp->curr_msg = init_estr(64);
  183.         hp->curr_ref = init_estr(64);
  184.         hp->whtspc = init_estr(0);
  185.  
  186. #if 0                           /* TODO:remove */
  187.         hp->filename_project = NULL;
  188.         hp->filename_document = NULL;
  189. #endif
  190.  
  191.         /* alloc message arrays */
  192.         hp->msg_ignore = (BOOL *)
  193.             umalloc((MAX_MSGID + 1) * sizeof(BOOL));
  194.         hp->msg_class = (HSCMSG_CLASS *)
  195.             umalloc((MAX_MSGID + 1) * sizeof(HSCMSG_CLASS));
  196.  
  197.         reset_hscprc(hp);
  198.     }
  199.     return (hp);
  200. }
  201.  
  202. /*
  203.  *
  204.  * GET-methodes for public item of HSCPRC
  205.  *
  206.  */
  207.  
  208. /*
  209.  * get flags
  210.  */
  211. BOOL hsc_get_chkid(HSCPRC * hp)
  212. {
  213.     return (hp->chkid);
  214. }
  215.  
  216. BOOL hsc_get_chkuri(HSCPRC * hp)
  217. {
  218.     return (hp->chkuri);
  219. }
  220.  
  221. BOOL hsc_get_compact(HSCPRC * hp)
  222. {
  223.     return (hp->compact);
  224. }
  225.  
  226. BOOL hsc_get_debug(HSCPRC * hp)
  227. {
  228.     return (hp->debug);
  229. }
  230.  
  231. BOOL hsc_get_getsize(HSCPRC * hp)
  232. {
  233.     return (hp->getsize);
  234. }
  235.  
  236. BOOL hsc_get_htmlonly(HSCPRC * hp)
  237. {
  238.     return (hp->htmlonly);
  239. }
  240.  
  241. BOOL hsc_get_jens(HSCPRC * hp)
  242. {
  243.     return (hp->jens);
  244. }
  245.  
  246. BOOL hsc_get_jerkvalues(HSCPRC * hp)
  247. {
  248.     return (hp->jerkvalues);
  249. }
  250.  
  251. BOOL hsc_get_rplc_ent(HSCPRC * hp)
  252. {
  253.     return (hp->rplc_ent);
  254. }
  255.  
  256. BOOL hsc_get_rplc_quote(HSCPRC * hp)
  257. {
  258.     return (hp->rplc_quote);
  259. }
  260.  
  261. BOOL hsc_get_smart_ent(HSCPRC * hp)
  262. {
  263.     return (hp->smart_ent);
  264. }
  265.  
  266. BOOL hsc_get_strip_badws(HSCPRC * hp)
  267. {
  268.     return (hp->strip_badws);
  269. }
  270.  
  271. BOOL hsc_get_strip_cmt(HSCPRC * hp)
  272. {
  273.     return (hp->strip_cmt);
  274. }
  275.  
  276. BOOL hsc_get_strip_ext(HSCPRC * hp)
  277. {
  278.     return (hp->strip_ext);
  279. }
  280.  
  281. /*
  282.  * get internal flags
  283.  */
  284. BOOL hsc_get_suppress_output(HSCPRC * hp)
  285. {
  286.     return (hp->suppress_output);
  287. }
  288.  
  289. BOOL hsc_get_inside_pre(HSCPRC * hp)
  290. {
  291.     return (hp->inside_pre);
  292. }
  293.  
  294. BOOL hsc_get_inside_anchor(HSCPRC * hp)
  295. {
  296.     return (hp->inside_anchor);
  297. }
  298.  
  299. BOOL hsc_get_fatal(HSCPRC * hp)
  300. {
  301.     return (hp->fatal);
  302. }
  303.  
  304. /*
  305.  * get values
  306.  */
  307. STRPTR hsc_get_destdir(HSCPRC * hp)
  308. {
  309.     return (estr2str(hp->destdir));
  310. }
  311.  
  312. STRPTR hsc_get_reldir(HSCPRC * hp)
  313. {
  314.     return (estr2str(hp->reldir));
  315. }
  316.  
  317. STRPTR hsc_get_iconbase(HSCPRC * hp)
  318. {
  319.     return (estr2str(hp->iconbase));
  320. }
  321.  
  322. /*
  323.  * get internal values
  324.  */
  325. STRPTR hsc_get_click_here_str(HSCPRC * hp)
  326. {
  327.     return (hp->click_here_str);
  328. }
  329.  
  330. STRPTR hsc_get_file_name(HSCPRC * hp)
  331. {
  332.     if (hp->inpf)
  333.         return (infget_fname(hp->inpf));
  334.     else
  335.         return (NULL);
  336. }
  337.  
  338. ULONG hsc_get_file_line(HSCPRC * hp)
  339. {
  340.     if (hp->inpf)
  341.         return (infget_y(hp->inpf));
  342.     else
  343.         return (0);
  344. }
  345.  
  346. ULONG hsc_get_file_column(HSCPRC * hp)
  347. {
  348.     if (hp->inpf)
  349.         return (infget_x(hp->inpf));
  350.     else
  351.         return (0);
  352. }
  353.  
  354. ULONG hsc_get_msg_count(HSCPRC * hp)
  355. {
  356.     return (hp->msg_count);
  357. }
  358.  
  359. /*
  360.  *
  361.  * SET-methodes for public item of HSCPRC
  362.  *
  363.  */
  364.  
  365. /*
  366.  * set values
  367.  */
  368. BOOL hsc_set_destdir(HSCPRC * hp, STRPTR dir)
  369. {
  370.     set_estr(hp->destdir, dir);
  371.     /* append "/" if neccessary */
  372.     link_fname(hp->destdir, estr2str(hp->destdir), "");
  373.     D(fprintf(stderr, DHL "destdir=`%s'\n", estr2str(hp->destdir)));
  374.  
  375.     return (TRUE);
  376. }
  377.  
  378. BOOL hsc_set_reldir(HSCPRC * hp, STRPTR dir)
  379. {
  380. #if 0
  381.     set_estr(hp->reldir, dir);
  382.     /* append "/" if neccessary */
  383.     link_fname(hp->reldir, estr2str(hp->reldir), "");
  384.     D(fprintf(stderr, DHL "reldir =`%s'\n", estr2str(hp->reldir)));
  385. #endif
  386.     /* append "/" if neccessary */
  387.     link_fname(hp->reldir, dir, "");
  388.     D(fprintf(stderr, DHL "reldir =`%s'\n", estr2str(hp->reldir)));
  389.  
  390.     return (TRUE);
  391. }
  392.  
  393. BOOL hsc_set_iconbase(HSCPRC * hp, STRPTR uri)
  394. {
  395.     set_estr(hp->iconbase, uri);
  396.  
  397.     D(fprintf(stderr, DHL "iconbase=`%s'\n", estr2str(hp->iconbase)));
  398.  
  399.     return (TRUE);
  400. }
  401.  
  402. BOOL hsc_set_strip_tags(HSCPRC * hp, STRPTR taglist)
  403. {
  404.     reallocstr(&(hp->strip_tags), taglist);
  405.     return (TRUE);
  406. }
  407.  
  408. BOOL hsc_set_filename_document(HSCPRC * hp, STRPTR filename)
  409. {
  410.     BOOL ok = FALSE;
  411.  
  412.     D(fprintf(stderr, DHL "document=`%s'\n", filename));
  413.     hp->filename_document = strclone(filename);
  414.  
  415.     return (ok);
  416. }
  417.  
  418. /*
  419.  * set flags
  420.  */
  421. VOID hsc_set_chkid(HSCPRC * hp, BOOL new_chkid)
  422. {
  423.     hp->chkid = new_chkid;
  424.     D(fprintf(stderr, DHL "flag: chkid    =%d\n", new_chkid));
  425. }
  426.  
  427. VOID hsc_set_chkuri(HSCPRC * hp, BOOL new_chkuri)
  428. {
  429.     hp->chkuri = new_chkuri;
  430.     D(fprintf(stderr, DHL "flag: chkuri   =%d\n", new_chkuri));
  431. }
  432.  
  433. VOID hsc_set_compact(HSCPRC * hp, BOOL new_compact)
  434. {
  435.     hp->compact = new_compact;
  436.     D(fprintf(stderr, DHL "flag: compact  =%d\n", new_compact));
  437. }
  438.  
  439. VOID hsc_set_debug(HSCPRC * hp, BOOL new_debug)
  440. {
  441.     hp->debug = new_debug;
  442.     D(fprintf(stderr, DHL "flag: debug    =%d\n", new_debug));
  443. }
  444.  
  445. VOID hsc_set_getsize(HSCPRC * hp, BOOL new_getsize)
  446. {
  447.     hp->getsize = new_getsize;
  448.     D(fprintf(stderr, DHL "flag: getsize  =%d\n", new_getsize));
  449. }
  450.  
  451. VOID hsc_set_htmlonly(HSCPRC * hp, BOOL new_htmlonly)
  452. {
  453.     hp->htmlonly = new_htmlonly;
  454.     D(fprintf(stderr, DHL "flag: htmlonly =%d\n", new_htmlonly));
  455. }
  456.  
  457. VOID hsc_set_jens(HSCPRC * hp, BOOL new_jens)
  458. {
  459.     hp->jens = new_jens;
  460.     D(fprintf(stderr, DHL "flag: jens     =%d\n", new_jens));
  461. }
  462.  
  463. VOID hsc_set_jerkvalues(HSCPRC * hp, BOOL new_jerkvalues)
  464. {
  465.     hp->jerkvalues = new_jerkvalues;
  466.     D(fprintf(stderr, DHL "flag: jerkval  =%d\n", new_jerkvalues));
  467. }
  468.  
  469. VOID hsc_set_rplc_ent(HSCPRC * hp, BOOL new_rplc_ent)
  470. {
  471.     hp->rplc_ent = new_rplc_ent;
  472.     D(fprintf(stderr, DHL "flag: rplc_ent =%d\n", new_rplc_ent));
  473. }
  474.  
  475. VOID hsc_set_rplc_quote(HSCPRC * hp, BOOL new_rplc_quote)
  476. {
  477.     hp->rplc_quote = new_rplc_quote;
  478.     D(fprintf(stderr, DHL "flag: rplc_quote =%d\n", new_rplc_quote));
  479. }
  480.  
  481. VOID hsc_set_smart_ent(HSCPRC * hp, BOOL new_smart_ent)
  482. {
  483.     hp->smart_ent = new_smart_ent;
  484.     D(fprintf(stderr, DHL "flag: smart_ent=%d\n", new_smart_ent));
  485. }
  486.  
  487. VOID hsc_set_strip_badws(HSCPRC * hp, BOOL new_strip_badws)
  488. {
  489.     hp->strip_badws = new_strip_badws;
  490.     D(fprintf(stderr, DHL "flag: strip_bws=%d\n", new_strip_badws));
  491. }
  492.  
  493. VOID hsc_set_strip_cmt(HSCPRC * hp, BOOL new_strip_cmt)
  494. {
  495.     hp->strip_cmt = new_strip_cmt;
  496.     D(fprintf(stderr, DHL "flag: strip_cmt=%d\n", new_strip_cmt));
  497. }
  498.  
  499. VOID hsc_set_strip_ext(HSCPRC * hp, BOOL new_strip_ext)
  500. {
  501.     hp->strip_ext = new_strip_ext;
  502.     D(fprintf(stderr, DHL "flag: strip_ext=%d\n", new_strip_ext));
  503. }
  504.  
  505. /*
  506.  * set flags
  507.  */
  508. VOID hsc_set_quote_mode(HSCPRC * hp, LONG new_mode)
  509. {
  510.     hp->quotemode = new_mode;
  511.     D(fprintf(stderr, DHL "quote_mode=%ld\n", new_mode));
  512. }
  513.  
  514. VOID hsc_set_entity_mode(HSCPRC * hp, LONG new_mode)
  515. {
  516.     hp->entmode = new_mode;
  517.     D(fprintf(stderr, DHL "entity_mode=%ld\n", new_mode));
  518. }
  519.  
  520. /*
  521.  * set call-backs
  522.  */
  523. VOID hsc_set_status_file_begin(HSCPRC * hp, VOID(*status_file) (HSCPRC * hp, STRPTR filename))
  524. {
  525.     hp->CB_status_file_begin = status_file;
  526. }
  527.  
  528. VOID hsc_set_status_file_end(HSCPRC * hp, VOID(*status_file) (HSCPRC * hp))
  529. {
  530.     hp->CB_status_file_end = status_file;
  531. }
  532.  
  533. VOID hsc_set_status_line(HSCPRC * hp, VOID(*status_line) (HSCPRC * hp))
  534. {
  535.     hp->CB_status_line = status_line;
  536. }
  537.  
  538. VOID hsc_set_status_misc(HSCPRC * hp, VOID(*status_misc) (HSCPRC * hp, STRPTR s))
  539. {
  540.     hp->CB_status_misc = status_misc;
  541. }
  542.  
  543. VOID hsc_set_message(
  544.                         HSCPRC * hp,
  545.                         VOID(*message) (struct hscprocess * hp,
  546.                                         HSCMSG_CLASS msg_class, HSCMSG_ID,
  547.                                         STRPTR fname, ULONG x, ULONG y,
  548.                                         STRPTR msg_text))
  549. {
  550.     hp->CB_message = message;
  551. }
  552.  
  553. VOID hsc_set_message_ref(
  554.                             HSCPRC * hp,
  555.                             VOID(*message_ref) (struct hscprocess * hp,
  556.                                    HSCMSG_CLASS msg_class, HSCMSG_ID msg_id,
  557.                                              STRPTR fname, ULONG x, ULONG y,
  558.                                                 STRPTR msg_text))
  559. {
  560.     hp->CB_message_ref = message_ref;
  561. }
  562.  
  563. VOID hsc_set_start_tag(HSCPRC * hp,
  564.                        VOID(*start_tag) (struct hscprocess * hp,
  565.           HSCTAG * tag, STRPTR tag_name, STRPTR tag_attr, STRPTR tag_close))
  566. {
  567.     hp->CB_start_tag = start_tag;
  568. }
  569.  
  570. VOID hsc_set_end_tag(HSCPRC * hp,
  571.                      VOID(*end_tag) (struct hscprocess * hp,
  572.           HSCTAG * tag, STRPTR tag_name, STRPTR tag_attr, STRPTR tag_close))
  573. {
  574.     hp->CB_end_tag = end_tag;
  575. }
  576.  
  577. VOID hsc_set_text(HSCPRC * hp,
  578.                   VOID(*text) (struct hscprocess * hp,
  579.                                STRPTR white_spaces, STRPTR text))
  580. {
  581.     hp->CB_text = text;
  582. }
  583.  
  584. VOID hsc_set_id(HSCPRC * hp,
  585.                 VOID(*id) (struct hscprocess * hp,
  586.                            HSCATTR * attr, STRPTR id))
  587. {
  588.     hp->CB_id = id;
  589. }
  590.  
  591. /*
  592.  * message methodes
  593.  */
  594. BOOL hsc_set_msg_ignore(HSCPRC * hp, HSCMSG_ID msg_id, BOOL value)
  595. {
  596.     BOOL set = FALSE;
  597.  
  598.     if ((msg_id & MASK_MESSAGE) <= MAX_MSGID)
  599.         hp->msg_ignore[msg_id & MASK_MESSAGE] = value;
  600.  
  601.     return (set);
  602. }
  603.  
  604. BOOL hsc_get_msg_ignore(HSCPRC * hp, HSCMSG_ID msg_id)
  605. {
  606.     /* HSCMSG_ID max_msgid = MAX_MSGID; */
  607.     if ((msg_id & MASK_MESSAGE) <= MAX_MSGID)
  608.         return (hp->msg_ignore[msg_id & MASK_MESSAGE]);
  609.     else
  610.         return (FALSE);
  611. }
  612.  
  613. BOOL hsc_set_msg_class(HSCPRC * hp, HSCMSG_ID msg_id, HSCMSG_CLASS msg_class)
  614. {
  615.     BOOL set = FALSE;
  616.  
  617.     if ((msg_id & MASK_MESSAGE) <= MAX_MSGID)
  618.         hp->msg_class[msg_id & MASK_MESSAGE] = msg_class;
  619.  
  620.     return (set);
  621. }
  622.  
  623. HSCMSG_CLASS hsc_get_msg_class(HSCPRC * hp, HSCMSG_ID msg_id)
  624. {
  625.     if ((msg_id & MASK_MESSAGE) <= MAX_MSGID)
  626.     {
  627.         HSCMSG_CLASS mchp = hp->msg_class[msg_id & MASK_MESSAGE];
  628.         HSCMSG_CLASS mcid = msg_id & MASK_MSG_CLASS;
  629.  
  630.         if (mcid > mchp)
  631.             return (mcid);
  632.         else
  633.             return (mchp);
  634.     }
  635.     else
  636.         return (MSG_NONE);
  637. }
  638.  
  639. /*
  640.  * set message classes to be ignored
  641.  */
  642. BOOL hsc_set_msg_ignore_notes(HSCPRC * hp, BOOL value)
  643. {
  644.     hp->msg_ignore_notes = value;
  645.     return (value);
  646. }
  647.  
  648. BOOL hsc_set_msg_ignore_style(HSCPRC * hp, BOOL value)
  649. {
  650.     hp->msg_ignore_style = value;
  651.     return (value);
  652. }
  653.  
  654. BOOL hsc_set_msg_ignore_port(HSCPRC * hp, BOOL value)
  655. {
  656.     hp->msg_ignore_port = value;
  657.     return (value);
  658. }
  659.  
  660. /*
  661.  * reset whole arrays for message-class/ignores
  662.  */
  663. VOID hsc_clear_msg_ignore(HSCPRC * hp)
  664. {
  665.     size_t i;
  666.     for (i = 0; i <= MAX_MSGID; i++)
  667.         hp->msg_ignore[i] = FALSE;
  668. }
  669.  
  670. VOID hsc_reset_msg_class(HSCPRC * hp)
  671. {
  672.     size_t i;
  673.     for (i = 0; i <= MAX_MSGID; i++)
  674.         hp->msg_class[i] = MSG_NONE;
  675. }
  676.  
  677. /*
  678.  * methods for include-directories
  679.  */
  680. BOOL hsc_add_include_directory(HSCPRC * hp, STRPTR dir)
  681. {
  682.     return ((BOOL) (app_strnode(hp->include_dirs, dir) != NULL));
  683. }
  684.  
  685. VOID hsc_clr_include_directory(HSCPRC * hp)
  686. {
  687.     clr_strlist(hp->include_dirs);
  688. }
  689.  
  690. /*
  691.  *-------------------------------------
  692.  * misc. funtions for white spaces
  693.  *-------------------------------------
  694.  */
  695.  
  696. /*
  697.  * compactWs - reduce white space string to blank
  698.  *             or linefeed
  699.  */
  700. STRPTR compactWs(HSCPRC * hp, STRPTR ws)
  701. {
  702.     STRPTR newWs = "";
  703.  
  704.     if (ws[0])
  705.     {
  706.         /* any white spaces at all */
  707.         STRPTR containsLF = strchr(ws, '\n');
  708.         STRPTR containsCR = strchr(ws, '\r');
  709.  
  710.         if (containsLF)
  711.             if (containsCR)
  712.                 newWs = "\r\n";
  713.             else
  714.                 newWs = "\n";
  715.         else if (containsCR)
  716.             newWs = "\r";
  717.         else
  718.             newWs = " ";
  719.     }
  720.  
  721.     return (newWs);
  722. }
  723.  
  724. /*
  725.  * output text function
  726.  *
  727.  * output text to host process
  728.  *
  729.  * params: hp....hsc process to perform ouput with
  730.  *         wspc..white spaces
  731.  *         text..other text
  732.  * result: true, if text has been outputted
  733.  */
  734. BOOL hsc_output_text(HSCPRC * hp, STRPTR wspc, STRPTR text)
  735. {
  736.     BOOL written = FALSE;
  737.     if ((hp)->CB_text && !((hp)->suppress_output))
  738.     {
  739.         /* add current white spaces to white space
  740.          * buffer; if hp->compact is enabled, reduce
  741.          * white spaces */
  742.         app_estr(hp->whtspc, wspc);
  743.         if (hp->compact && (!hp->inside_pre))
  744.         {
  745.             /* reduce white spaces */
  746.             wspc = compactWs(hp, estr2str(hp->whtspc));
  747.         }
  748.         else
  749.         {
  750.             wspc = estr2str(hp->whtspc);
  751.         }
  752.  
  753.         /* strip white spaces if requested */
  754.         if (hp->strip_next_whtspc)
  755.         {
  756.             D(fprintf(stderr, DHL "bad white spaces stripped\n"));
  757.             hp->strip_next_whtspc = FALSE;
  758.             wspc = "";
  759.         } else if (hp->strip_next2_whtspc)
  760.         {
  761.             hp->strip_next2_whtspc = FALSE;
  762.             hp->strip_next_whtspc = TRUE;
  763.         }
  764.  
  765. #if DEBUG_HSCLIB_OUTPUT
  766.         if (hp->debug)
  767.             if (text)
  768.                 if (strcmp(text, "\n"))
  769.                     fprintf(stderr, DHL "ouput: `%s', `%s'\n", wspc, text);
  770.                 else
  771.                     fprintf(stderr, DHL "ouput: `%s', `\\n'\n", wspc);
  772. #endif
  773.         if ((wspc && wspc[0]) || (text && text[0]))
  774.         {
  775.             (*((hp)->CB_text)) ((hp), wspc, text);
  776.             written = TRUE;
  777.         }
  778.  
  779.         /* reset white space buffer */
  780.         clr_estr(hp->whtspc);
  781.  
  782.     }
  783.     return (written);
  784. }
  785.  
  786. /*
  787.  * misc. functions
  788.  */
  789.  
  790. /*
  791.  * nomem-handler
  792.  */
  793. BOOL hsc_standard_nomem_handler(size_t size)
  794. {                               /* TODO: think about this */
  795.     fputs("\n*** out of memory\n\n", stderr);
  796.  
  797.     exit(RC_FAIL);
  798.  
  799.     return (FALSE);             /* abort immediatly */
  800. }
  801.  
  802.